//
//  SEGInviteRecordCell.m
//  ExcellentHome
//
//  Created by 揭婧雯 on 2017/2/27.
//  Copyright © 2017年 陈区. All rights reserved.
//

#import "SEGInviteRecordCell.h"

@implementation SEGInviteRecordCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString*)reuseIdentifier
{
    
    if (self == [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        [self setupUI];
    }
    return self;
}

- (void)setupUI
{
    NSNumber *f1 = @98.0;
    NSNumber *f2 = @51.0;
    //适配小屏
    if (LYScreenWidth() < 375.0) {
        f1 = @([f1 doubleValue] * kScaleWidth);
        f2 = @([f2 doubleValue] * kScaleWidth);
    }
    NSArray *widths = @[f1,f1,f1,f2]; //列宽
    CGFloat leftPadding = 15;
    for (int i = 0; i < 4; i++) {
        UILabel *label = [[UILabel alloc] init];
//        label.backgroundColor = [UIColor redColor];
        label.font = [UIFont systemFontOfSize:11];
        label.textColor = kColor_1;
        label.textAlignment = NSTextAlignmentCenter;
        [self.contentView addSubview:label];
        [label mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView.mas_left).with.offset(leftPadding+3);
            make.top.equalTo(self.contentView.mas_top).with.offset(13).priorityLow();
            make.width.mas_equalTo([widths[i] floatValue] - 6);
            make.height.mas_equalTo(15);
        }];
        leftPadding = leftPadding + [widths[i] floatValue];
        
        switch (i) {
            case 0:
                label.text = @"昵称";
                self.nameLabel = label;
                break;
            case 1:
                label.text = @"手机";
                self.phoneLabel = label;
                break;
            case 2:
                label.text = @"奖励";
                self.awardLabel = label;
                break;
            case 3:
                label.text = @"状态";
                self.statusLabel = label;
                break;
        }
    }
    
    self.bottomLine = [[UIView alloc] init];
    self.bottomLine.backgroundColor = kColor_L2;
    [self.contentView addSubview:self.bottomLine];
    [self.bottomLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView.mas_left);
        make.right.equalTo(self.contentView.mas_right);
        make.bottom.equalTo(self.contentView.mas_bottom);
        make.height.mas_equalTo(0.5);
    }];
    self.bottomLine.hidden = YES;
}

- (void)updateWithDetailModel:(SEGInviteRecordDetailModel *)model
{
    self.nameLabel.text = model.username;
    self.phoneLabel.text = model.phone;
    self.awardLabel.text = model.award;
    self.statusLabel.text = model.status;
    if ([model.winStatus isEqualToString:@"2"]) {//已删除
        self.nameLabel.textColor = kColor_L2;
        self.phoneLabel.textColor = kColor_L2;
        self.awardLabel.textColor = kColor_L2;
        self.statusLabel.textColor = kColor_L2;
    }else {
        self.nameLabel.textColor = kColor_1;
        self.phoneLabel.textColor = kColor_1;
        self.awardLabel.textColor = kColor_1;
        self.statusLabel.textColor = kColor_1;
    }
}

- (void)updateUIToCenterY
{
    [self.nameLabel mas_updateConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.contentView.mas_centerY);
    }];
    [self.phoneLabel mas_updateConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.contentView.mas_centerY);
    }];
    [self.awardLabel mas_updateConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.contentView.mas_centerY);
    }];
    [self.statusLabel mas_updateConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.contentView.mas_centerY);
    }];
}
@end
